package com.infodms.dms.dao.claim.authorization;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.claim.application.BalanceStatusRecord;
import com.infodms.dms.bean.TtIfMarketBean;
import com.infodms.dms.bean.auditBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.Utility;
import com.infodms.dms.dao.claim.dealerClaimMng.ClaimBillMaintainDAO;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.dao.partinfo.PartinfoDao;
import com.infodms.dms.po.TtAsChangedatePO;
import com.infodms.dms.po.TtAsWrBalanceAuthitemPO;
import com.infodms.dms.po.TtAsWrClaimBalancePO;
import com.infodms.dms.po.TtAsWrGatherBalancePO;
import com.infodms.dms.po.TtIfStandardPO;
import com.infodms.dms.util.StringUtil;
import com.infoservice.po3.POFactory;
import com.infoservice.po3.POFactoryBuilder;
import com.infoservice.po3.bean.PageResult;
import com.lowagie.tools.concat_pdf;

@SuppressWarnings("unchecked")
public class BalanceMainDao extends BaseDao {
	public static Logger logger = Logger.getLogger(PartinfoDao.class);
	
	protected TtIfStandardPO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public PageResult<Map<String, Object>> queryAccAuditList(auditBean bean,int curPage, int pageSize){
		StringBuffer sql= new StringBuffer();

		sql.append("WITH person as (\n");
		sql.append("select distinct aa.balance_id,aa.auth_person_name,auth_status from tt_as_wr_balance_authitem aa where aa.auth_status=11861004\n" );
		sql.append(")");

		sql.append("SELECT /*+RULE*/ROWNUM NUM,r.region_name, a.ID, a.BALANCE_NO, a.DEALER_CODE, a.DEALER_NAME, NVL(a.CLAIM_COUNT,0) AS CLAIM_COUNT,\n" );
		sql.append("       TO_CHAR(a.CREATE_DATE, 'YYYY-MM-DD') CREATE_DATE, a.STATUS ,NVL(a.SPEC_FEE_COUNT,0) SPEC_FEE_COUNT,");
		sql.append("       NVL(a.SPEC_FEE_AUTH_COUNT,0) SPEC_FEE_AUTH_COUNT,TO_CHAR(t.BEGIN_BALANCE_DATE,'YYYY-MM-DD') AS BEGIN_BALANCE_DATE,TO_CHAR(t.END_BALANCE_DATE,'YYYY-MM-DD') AS END_BALANCE_DATE,\n" );
		
		/*********add by liuxh 20101127 增加索赔单已审核数量，特殊费用单数量和已审核数量************/
		sql.append("(SELECT COUNT (1) FROM tt_as_wr_application b, tr_balance_claim c WHERE b.ID = c.claim_id\n ");
		sql.append(" AND c.balance_id = a.ID AND b.status = "+Constant.CLAIM_APPLY_ORD_TYPE_07+") AS claim_count_al,\n");
		sql.append("(SELECT COUNT(1) FROM TT_AS_WR_SPEFEE D WHERE D.CLAIMBALANCE_ID=A.ID) AS SP_COUNT,\n");
		sql.append("(SELECT COUNT(1) FROM TT_AS_WR_SPEFEE D WHERE D.CLAIMBALANCE_ID=A.ID AND D.STATUS IN("+Constant.SPEFEE_STATUS_06+","+Constant.SPEFEE_STATUS_05+")) AS SP_COUNT_AL,\n");
		/*********add by liuxh 20101127 增加索赔单已审核数量，特殊费用单数量和已审核数量**********/
		
		sql.append("TO_CHAR(a.START_DATE,'YYYY-MM-DD') AS START_DATE,TO_CHAR(a.END_DATE,'YYYY-MM-DD') AS END_DATE, p.auth_person_name\n");
		sql.append(" FROM TT_AS_WR_CLAIM_BALANCE a ,tm_dealer t,tm_region r ,person p\n");
		sql.append("WHERE a.OEM_COMPANY_ID = ").append(bean.getOemCompanyId()).append("\n");
		sql.append(" AND a.YIELDLY IN (").append(bean.getYieldlys()).append(") and a.dealer_id=t.dealer_id\n");
		sql.append(" and t.province_id = r.region_code\n");
		if(Utility.testString(bean.getDealerCode())){
			//拼字符串(同时查询多个经销商，不可模糊)sql.append("AND a.DEALER_CODE IN (").append(bean.getDealerCode()).append(")\n");
			sql.append("AND a.DEALER_CODE LIKE '%").append(bean.getDealerCode()).append("%'\n");
		}
		
		if(Utility.testString(bean.getStartDate())){
			sql.append("AND a.CREATE_DATE >= TO_DATE('").append(bean.getStartDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getEndDate())){
			sql.append("AND a.CREATE_DATE <= TO_DATE('").append(bean.getEndDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getYieldly())){
			sql.append("AND a.YIELDLY = ").append(bean.getYieldly()).append("\n");
		}
		if(Utility.testString(bean.getBalanceNo())){
			sql.append("AND a.BALANCE_NO LIKE '%").append(bean.getBalanceNo()).append("%'\n");
		}
		if(Utility.testString(bean.getStatus())){
			sql.append("AND a.STATUS = ").append(bean.getStatus()).append("\n");
		}else{
			sql.append("and a.status not in ("+Constant.ACC_STATUS_01+","+Constant.ACC_STATUS_07+","+Constant.ACC_STATUS_08+","+Constant.ACC_STATUS_09+")\n");
		}
		sql.append("and  a.id=p.balance_id(+)");
		if(Utility.testString(bean.getPerson())){
			sql.append("and p.auth_person_name='"+bean.getPerson()+"'");
		}
		sql.append(" order by a.update_date desc\n");
		

		System.out.println("sqlsql=="+sql);
		PageResult<Map<String, Object>> ps = pageQuery(sql.toString(), null, getFunName(), pageSize, curPage);
		return ps;
	}
	
	public PageResult<Map<String, Object>> queryDealerBalanceList(auditBean bean,int curPage, int pageSize){
		StringBuffer sql= new StringBuffer();
		sql.append("SELECT ROWNUM NUM, A.ID, A.BALANCE_NO, A.DEALER_CODE, A.DEALER_NAME, A.CLAIM_COUNT,\n" );
		sql.append("       TO_CHAR(A.CREATE_DATE, 'YYYY-MM-DD') CREATE_DATE, \n" );
		sql.append("	   TO_CHAR(A.BALANCE_AMOUNT, 'FM99,999,990.00') BALANCE_AMOUNT,\n");
		sql.append("	   TO_CHAR(A.FINANCIAL_DEDUCT, 'FM99,999,990.00') FINANCIAL_DEDUCT,\n");
		sql.append("	   TO_CHAR(A.NOTE_AMOUNT, 'FM99,999,990.00') NOTE_AMOUNT,\n");
		sql.append("	   A.FUNANCIAL_REMARK, A.STATUS,A.INVOICE_MAKER,TO_CHAR(A.START_DATE,'YYYY-MM-DD') START_DATE,\n");
		sql.append("	   TO_CHAR(A.END_DATE,'YYYY-MM-DD') END_DATE,C.AUTH_PERSON_NAME,TO_CHAR(C.CREATE_DATE,'YYYY-MM-DD') AUTH_DATE\n");
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A,TT_LABOR_LIST_DETAIL B,TT_TAXABLE_SUM_AUTHITEM C\n");
		sql.append(" WHERE 1 = 1\n" );
		sql.append(" AND A.BALANCE_NO = B.BALANCE_NO(+)\n" );
		sql.append(" AND B.REPORT_ID = C.BALANCE_ID(+)\n" );
		sql.append(" AND C.AUTH_STATUS(+) = "+Constant.TAXABLE_SERVICE_SUM_GET+"\n");
		
		/******mod by liuxh 20101115 ******/
		//sql.append("AND A.DEALER_ID = ").append(bean.getDealerCode()).append("\n");
		sql.append("AND A.TOP_DEALER_ID = ").append(bean.getDealerCode()).append("\n");
		/******mod by liuxh 20101115 ******/
		
		if(Utility.testString(bean.getStartDate())){
			sql.append("AND A.CREATE_DATE >= TO_DATE('").append(bean.getStartDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getEndDate())){
			sql.append("AND A.CREATE_DATE <= TO_DATE('").append(bean.getEndDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getYieldly())){
			sql.append("AND A.YIELDLY = ").append(bean.getYieldly()).append("\n");
		}
		if(Utility.testString(bean.getBalanceNo())){
			sql.append("AND A.BALANCE_NO LIKE '%").append(bean.getBalanceNo()).append("%'\n");
		}
		if(Utility.testString(bean.getOemCompanyId())){
			sql.append("AND A.OEM_COMPANY_ID = ").append(bean.getOemCompanyId()).append("\n");
		}
		sql.append("AND A.STATUS IN (").append(Constant.ACC_STATUS_04).append(",").append(Constant.ACC_STATUS_05).append(")\n");

		PageResult<Map<String, Object>> ps = pageQuery(sql.toString(), null, getFunName(), pageSize, curPage);
		return ps;
	} 
	
	public PageResult<Map<String, Object>> queryOemBalanceList(auditBean bean,int curPage, int pageSize){
		StringBuffer sql= new StringBuffer();
		sql.append("SELECT ROWNUM NUM,r.region_name, A.ID, A.BALANCE_NO, A.DEALER_CODE, A.DEALER_NAME, A.CLAIM_COUNT,\n" );
		sql.append("        to_char(ba.auth_time,'YYYY-MM-DD') create_date, \n" );
		sql.append("	   TO_CHAR(A.BALANCE_AMOUNT, 'FM99,999,990.00') BALANCE_AMOUNT,\n");
		sql.append("	   TO_CHAR(A.FINANCIAL_DEDUCT, 'FM99,999,990.00') FINANCIAL_DEDUCT,\n");
		sql.append("	   TO_CHAR(A.NOTE_AMOUNT, 'FM99,999,990.00') NOTE_AMOUNT,\n");
		sql.append("	   A.FUNANCIAL_REMARK, A.STATUS,A.INVOICE_MAKER,TO_CHAR(A.START_DATE,'YYYY-MM-DD') START_DATE,\n");
		sql.append("	   TO_CHAR(A.END_DATE,'YYYY-MM-DD') END_DATE,C.AUTH_PERSON_NAME,TO_CHAR(C.CREATE_DATE,'YYYY-MM-DD') AUTH_DATE\n");
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A,TT_LABOR_LIST_DETAIL B,TT_TAXABLE_SUM_AUTHITEM C,tm_region r,Tt_As_Wr_Balance_Authitem ba \n");
		sql.append(" WHERE 1 = 1\n" );
		sql.append(" AND A.BALANCE_NO = B.BALANCE_NO(+)\n" );
		sql.append(" AND B.REPORT_ID = C.BALANCE_ID(+)\n" );
		sql.append(" and r.region_code = a.province\n");
		sql.append("and ba.balance_id = a.id\n" );
		sql.append("and ba.auth_status=11861007");

		sql.append(" AND C.AUTH_STATUS(+) = "+Constant.TAXABLE_SERVICE_SUM_GET+"\n");
		sql.append(" AND A.STATUS IN (").append(Constant.ACC_STATUS_04).append(",").append(Constant.ACC_STATUS_05).append(")\n");
		sql.append(" AND A.YIELDLY IN (").append(bean.getYieldlys()).append(")\n");
		
		if(Utility.testString(bean.getStartDate())){
			sql.append("AND ba.auth_time >= TO_DATE('").append(bean.getStartDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getEndDate())){
			sql.append("AND ba.auth_time <= TO_DATE('").append(bean.getEndDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getYieldly())){
			sql.append("AND A.YIELDLY = ").append(bean.getYieldly()).append("\n");
		}
		if(Utility.testString(bean.getBalanceNo())){
			sql.append("AND A.BALANCE_NO LIKE '%").append(bean.getBalanceNo()).append("%'\n");
		}
		if(Utility.testString(bean.getOemCompanyId())){
			sql.append("AND A.OEM_COMPANY_ID = ").append(bean.getOemCompanyId()).append("\n");
		}
		if(Utility.testString(bean.getDealerId())){
			sql.append("AND A.DEALER_ID IN (").append(bean.getDealerId()).append(")\n");
		}

		sql.append("ORDER BY A.ID DESC");
		PageResult<Map<String, Object>> ps = pageQuery(sql.toString(), null, getFunName(), pageSize, curPage);
		return ps;
	}
	
	public PageResult<Map<String, Object>> queryFinancialMain(auditBean bean,int curPage, int pageSize){
		StringBuffer sql= new StringBuffer();
		sql.append("SELECT /*+INDEX(TT_AS_WR_CLAIM_BALANCE,IDX_TT_CLAIM_BALANCE_STATUS)*/ROWNUM NUM, ID, BALANCE_NO, DEALER_CODE, DEALER_NAME, CLAIM_COUNT,\n" );
		sql.append("       TO_CHAR(CREATE_DATE, 'YYYY-MM-DD') CREATE_DATE, STATUS,REVIEW_APPLICATION_BY,TO_CHAR(REVIEW_APPLICATION_TIME,'YYYY-MM-DD') AS REVIEW_APPLICATION_TIME\n" );
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE\n");
		sql.append("WHERE OEM_COMPANY_ID = ").append(bean.getOemCompanyId()).append("\n");
		sql.append(" AND YIELDLY IN (").append(bean.getYieldlys()).append(")\n");
		
		if(Utility.testString(bean.getDealerCode())){
			//拼字符串(同时查询多个经销商，不可模糊)sql.append("AND DEALER_CODE IN (").append(bean.getDealerCode()).append(")\n");
			sql.append("AND DEALER_CODE LIKE '%").append(bean.getDealerCode()).append("%'\n");
		}
		/*********iverson add by 2011-01-20***************/
		if(Utility.testString(bean.getReviewBy())){
			sql.append("AND REVIEW_APPLICATION_BY LIKE '%").append(bean.getReviewBy()).append("%'\n");
		}
		if(Utility.testString(bean.getReviewBeginDate())){
			sql.append("AND REVIEW_APPLICATION_TIME >= TO_DATE('").append(bean.getReviewBeginDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getReviewEndDate())){
			sql.append("AND REVIEW_APPLICATION_TIME <= TO_DATE('").append(bean.getReviewEndDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		/*********iverson add by 2011-01-20***************/
		if(Utility.testString(bean.getStartDate())){
			sql.append("AND CREATE_DATE >= TO_DATE('").append(bean.getStartDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getEndDate())){
			sql.append("AND CREATE_DATE <= TO_DATE('").append(bean.getEndDate()).append("', 'YYYY-MM-DD HH24:MI:SS')\n");
		}
		if(Utility.testString(bean.getYieldly())){
			sql.append("AND YIELDLY = ").append(bean.getYieldly()).append("\n");
		}
		if(Utility.testString(bean.getBalanceNo())){
			sql.append("AND BALANCE_NO LIKE '%").append(bean.getBalanceNo()).append("%'\n");
		}
		if(Utility.testString(bean.getStatus())){
			sql.append("AND STATUS = ").append(bean.getStatus());
		}else{
			sql.append("and status not in ("+Constant.ACC_STATUS_07+","+Constant.ACC_STATUS_08+","+Constant.ACC_STATUS_09+")\n");
		}
		
		//sql.append("AND STATUS IN ( ").append(Constant.ACC_STATUS_03).append(",").append(Constant.ACC_STATUS_04).append(")\n");
		
		PageResult<Map<String, Object>> ps = pageQuery(sql.toString(), null, getFunName(), pageSize, curPage);
		return ps;
	}
	
	public Map<String, Object> getBalanceMainMap(String id){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT A.*, NVL(D.DAMOUNT, 0) DAMOUNT,\n" );
		sql.append("       TO_CHAR(A.CREATE_DATE, 'YYYY-MM-DD') CREATEDATE,\n" );
		sql.append("       TO_CHAR(A.START_DATE, 'YYYY-MM-DD') STARTDATE,\n" );
		sql.append("       TO_CHAR(A.END_DATE, 'YYYY-MM-DD') ENDDATE,\n" );
		/*
		sql.append("	   (NVL(E.DECLARE_SUM1, 0) + NVL(A.APPEND_AMOUNT, 0)) DECLARE_SUM1, \n");
		sql.append("       NVL(F.DECLARE_SUM2, 0) DECLARE_SUM2, \n");
		*/
		sql.append("	   (NVL(A.MARKET_AMOUNT, 0) + NVL(A.APPEND_AMOUNT, 0)) DECLARE_SUM1, \n");
		sql.append("       NVL(A.SPEOUTFEE_AMOUNT, 0) DECLARE_SUM2, \n");
		sql.append("	   (NVL(A.SERVICE_FIXED_AMOUNT, 0) + NVL(A.SERVICE_LABOUR_AMOUNT, 0) + NVL(A.SERVICE_PART_AMOUNT, 0) + NVL(A.SERVICE_OTHER_AMOUNT, 0)) SERVICE_AMOUNT,");
		sql.append("       NVL(B.TOTAL_AMOUNT, 0) TOTAL_AMOUNT, NVL(C.FINE_SUM, 0) FINE_SUM, \n" );
		sql.append("       (NVL(B.TOTAL_AMOUNT, 0) + NVL(C.FINE_SUM, 0) + NVL(D.DAMOUNT, 0)) TAMOUNT, \n");
		sql.append("	   (A.AMOUNT_SUM) AMOUNTSUM,\n");
		sql.append("	   (A.AMOUNT_SUM - NVL(B.TOTAL_AMOUNT, 0) - NVL(C.FINE_SUM, 0) - NVL(D.DAMOUNT, 0)) AAMOUNT\n");
		/*
		sql.append("	   (A.AMOUNT_SUM + NVL(E.DECLARE_SUM1, 0) + NVL(F.DECLARE_SUM2, 0)) AMOUNTSUM,\n");
		sql.append("	   (A.AMOUNT_SUM + NVL(E.DECLARE_SUM1, 0) + NVL(F.DECLARE_SUM2, 0) - NVL(B.TOTAL_AMOUNT, 0) - NVL(C.FINE_SUM, 0) - NVL(D.DAMOUNT, 0)) AAMOUNT\n");
		*/
		sql.append("	   ,(NVL(A.APPLY_AMOUNT,0)-NVL(A.BALANCE_AMOUNT,0)) AUTHDEDUCT\n");
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A,\n" );
		sql.append("     (\n" );
		sql.append("      SELECT DEALER_CODE,YIELDLY, SUM(TOTAL_AMOUNT) TOTAL_AMOUNT\n" );
		sql.append("      FROM TT_AS_WR_DEDUCT_BALANCE\n" );
		sql.append("      WHERE STATUS = ").append(Constant.STATUS_ENABLE).append("\n");
		sql.append("      GROUP BY DEALER_CODE,YIELDLY\n" );
		sql.append("      ) B,\n" );
		sql.append("     (\n" );
		sql.append("      SELECT DEALER_ID,YIELDLY, SUM(FINE_SUM) FINE_SUM\n" );
		sql.append("      FROM TT_AS_WR_FINE\n" );
		sql.append("      WHERE PAY_STATUS = ").append(Constant.PAY_STATUS_01).append("\n");
		sql.append("      GROUP BY DEALER_ID,YIELDLY\n" );
		sql.append("      ) C,\n" );
		sql.append("	 (\n");
		sql.append("	  SELECT DEALER_ID,YIELDLY, SUM(DEDUCT_AMOUNT) DAMOUNT\n");
		sql.append("	  FROM TT_AS_WR_ADMIN_DEDUCT\n");
		sql.append("	  WHERE DEDUCT_STATUS = ").append(Constant.ADMIN_STATUS_01).append("\n");
		sql.append("      AND CLAIMBALANCE_ID IS NULL \n");
		sql.append("	  GROUP BY DEALER_ID,YIELDLY\n");
		sql.append("	  ) D\n");
		//2010-11-04 屏蔽  现在特殊外出费用和市场工单费用已经在结算单生成时加入加入结算单中
		/*		
        sql.append("	 (\n");
		sql.append("	  SELECT DEALER_ID,YIELD, SUM(DECLARE_SUM) DECLARE_SUM1\n" );
		sql.append("      FROM TT_AS_WR_SPEFEE A\n" );
		sql.append("      WHERE A.FEE_TYPE = ").append(Constant.FEE_TYPE_01).append("\n");
		sql.append("      AND A.STATUS = ").append(Constant.SPEFEE_STATUS_06).append("\n");
		sql.append("      GROUP BY DEALER_ID,YIELD\n");
		sql.append("      ) E, \n");
		sql.append("	 (\n");
		sql.append("	  SELECT DEALER_ID,YIELD, SUM(DECLARE_SUM) DECLARE_SUM2\n" );
		sql.append("      FROM TT_AS_WR_SPEFEE A\n" );
		sql.append("      WHERE A.FEE_TYPE = ").append(Constant.FEE_TYPE_02).append("\n");
		sql.append("      AND A.STATUS = ").append(Constant.SPEFEE_STATUS_06).append("\n");
		sql.append("      GROUP BY DEALER_ID,YIELD\n");
		sql.append("      ) F \n");*/
		sql.append("WHERE A.DEALER_CODE = B.DEALER_CODE(+)\n" );
		sql.append("AND A.YIELDLY = B.YIELDLY(+)");
		sql.append("AND A.DEALER_ID = C.DEALER_ID(+)\n" );
		sql.append("AND A.YIELDLY = C.YIELDLY(+)\n" );
		sql.append("AND A.DEALER_ID = D.DEALER_ID(+)\n" );
		sql.append("AND A.YIELDLY = D.YIELDLY(+)\n" );
		/*
		sql.append("AND A.DEALER_ID = E.DEALER_ID(+)\n");
		sql.append("AND A.YIELDLY = E.YIELD(+)\n" );
		sql.append("AND A.DEALER_ID = F.DEALER_ID(+)\n");
		sql.append("AND A.YIELDLY = F.YIELD(+)\n" );
		*/
		sql.append("AND A.ID = ").append(id).append("\n");
		sql.append("ORDER BY A.CREATE_DATE DESC\n");

		Map<String, Object> map = pageQueryMap(sql.toString(), null, getFunName());
		return map;
	}
	
	public Map<String, Object> getBalanceMainMapView(String id){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT B.AUTH_PERSON_NAME,B.AUTH_TIME,b.auth_status,A.*, (NVL(A.FREE_DEDUCT,0) + NVL(A.SERVICE_DEDUCT, 0) + NVL(A.CHECK_DEDUCT,0) + NVL(A.OLD_DEDUCT,0) + NVL(A.ADMIN_DEDUCT,0)) DEDUCT,\n" );
		sql.append("       TO_CHAR(A.CREATE_DATE, 'YYYY-MM-DD') CREATEDATE,\n" );
		sql.append("       TO_CHAR(A.START_DATE, 'YYYY-MM-DD') STARTDATE,\n" );
		sql.append("	   (NVL(A.MARKET_AMOUNT, 0) + NVL(A.APPEND_AMOUNT, 0)) DECLARE_SUM1, \n");
		/*********add by liuxh 20101209 增加汇总结算单打印取值***********/
		sql.append("      (SELECT K.DEALER_CODE FROM TM_DEALER K WHERE K.DEALER_ID=A.DEALER_ID) AS DEALER_CODE_WX,"); //维修站代码
		sql.append("      (SELECT K.DEALER_NAME FROM TM_DEALER K WHERE K.DEALER_ID=A.DEALER_ID) AS DEALER_NAME_WX,"); //维修站名称
		sql.append("      (SELECT K.DEALER_CODE FROM TM_DEALER K WHERE K.DEALER_ID=A.KP_DEALER_ID) AS DEALER_CODE_KP,A.STATIONER_TEL,"); //开票单位代码 . 站长电话
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS SQ_REPAIR,\n"); //售前维修
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS YB_REPAIR,\n"); //一般维修
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS WC_REPAIR,\n"); //外出维修
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS BY_REPAIR,\n"); //免费保养
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS FW_REPAIR,\n"); //服务活动
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_OUT_COUNT,\n"); //特殊外出数量
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_FEE_COUNT,\n"); //特殊费用数量
		sql.append("      ((SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID)+");//总单据数 索赔单+特殊费用
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.CLAIMBALANCE_ID=A.ID)) AS ALL_COUNT,");//总单据数 索赔单+特殊费用
		
		sql.append("      (SELECT SUM(NVL(K.DECLARE_SUM,0)) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_FEE_MARKET,\n"); //特殊外出费用
		sql.append("      (SELECT SUM(NVL(K.DECLARE_SUM,0)) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_FEE_OUT,\n"); //特殊费用 市场公单
		
		/*********add by liuxh 20101209 增加汇总结算单打印取值***********/
		sql.append("	   (NVL(A.SERVICE_FIXED_AMOUNT, 0) + NVL(A.SERVICE_LABOUR_AMOUNT, 0) + NVL(A.SERVICE_PART_AMOUNT, 0) + NVL(A.SERVICE_OTHER_AMOUNT, 0)) SERVICE_AMOUNT,");
		sql.append("       TO_CHAR(A.END_DATE, 'YYYY-MM-DD') ENDDATE,\n" );
		sql.append("	   NVL(A.NOTE_AMOUNT, A.BALANCE_AMOUNT) NOTEAMOUNT,a.invoice_maker\n");
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A\n" );
		sql.append(" LEFT OUTER JOIN TT_AS_WR_BALANCE_AUTHITEM B ON A.ID=B.BALANCE_ID \n");
		sql.append("WHERE A.ID = ? \n");
		sql.append(" order by b.auth_time desc");
		
		List parList=new ArrayList();
		parList.add(Constant.CLA_TYPE_07);//售前维修
		parList.add(Constant.CLA_TYPE_01);//一般维修
		parList.add(Constant.CLA_TYPE_09);//外出维修
		parList.add(Constant.CLA_TYPE_02);//免费保养
		parList.add(Constant.CLA_TYPE_06);//服务活动
		parList.add(Constant.FEE_TYPE_02);//特殊费用 外出
		parList.add(Constant.FEE_TYPE_01);//特殊费用  市场公单
		parList.add(Constant.FEE_TYPE_02);//特殊费用 外出
		parList.add(Constant.FEE_TYPE_01);//特殊费用  市场公单
		parList.add(Long.valueOf(id));
		
		Map<String, Object> map = pageQueryMap(sql.toString(), parList, getFunName());
		return map;
	}
	public Map<String, Object> getBalanceMainMapView2(String id){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT B.AUTH_PERSON_NAME,B.AUTH_TIME,b.auth_status,A.*, (NVL(A.FREE_DEDUCT,0) + NVL(A.SERVICE_DEDUCT, 0) + NVL(A.CHECK_DEDUCT,0) + NVL(A.OLD_DEDUCT,0) + NVL(A.ADMIN_DEDUCT,0)) DEDUCT,\n" );
		sql.append("       TO_CHAR(A.CREATE_DATE, 'YYYY-MM-DD') CREATEDATE,\n" );
		sql.append("       TO_CHAR(A.START_DATE, 'YYYY-MM-DD') STARTDATE,\n" );
		sql.append("	   (NVL(A.MARKET_AMOUNT_bak, 0) + NVL(A.APPEND_AMOUNT_bak, 0)) DECLARE_SUM1, \n");
		sql.append("     (select O.REGION_NAME FROM TM_REGION O WHERE O.REGION_CODE = A.PROVINCE) as PROVINCE_NAME,");
		/*********add by liuxh 20101209 增加汇总结算单打印取值***********/
		sql.append("      (SELECT K.DEALER_CODE FROM TM_DEALER K WHERE K.DEALER_ID=A.DEALER_ID) AS DEALER_CODE_WX,"); //维修站代码
		sql.append("      (SELECT K.DEALER_NAME FROM TM_DEALER K WHERE K.DEALER_ID=A.DEALER_ID) AS DEALER_NAME_WX,"); //维修站名称
		sql.append("      (SELECT K.DEALER_CODE FROM TM_DEALER K WHERE K.DEALER_ID=A.KP_DEALER_ID) AS DEALER_CODE_KP,A.STATIONER_TEL,"); //开票单位代码 . 站长电话
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS SQ_REPAIR,\n"); //售前维修
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS YB_REPAIR,\n"); //一般维修
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS WC_REPAIR,\n"); //外出维修
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS BY_REPAIR,\n"); //免费保养
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID AND K.CLAIM_TYPE=?) AS FW_REPAIR,\n"); //服务活动
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_OUT_COUNT,\n"); //特殊外出数量
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_FEE_COUNT2,\n"); //特殊费用数量
		sql.append("      ((SELECT COUNT(1) FROM TT_AS_WR_APPLICATION K,TR_BALANCE_CLAIM L WHERE K.ID=L.CLAIM_ID AND L.BALANCE_ID=A.ID)+");//总单据数 索赔单+特殊费用
		sql.append("      (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.CLAIMBALANCE_ID=A.ID)) AS ALL_COUNT,");//总单据数 索赔单+特殊费用
		
		sql.append("      (SELECT SUM(NVL(K.DECLARE_SUM,0)) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_FEE_MARKET,\n"); //特殊外出费用
		sql.append("      (SELECT SUM(NVL(K.DECLARE_SUM,0)) FROM TT_AS_WR_SPEFEE K WHERE K.FEE_TYPE=? AND K.CLAIMBALANCE_ID=A.ID) AS SPEC_FEE_OUT,\n"); //特殊费用 市场公单
		
		/*********add by liuxh 20101209 增加汇总结算单打印取值***********/
		sql.append("	   (NVL(A.SERVICE_FIXED_AMOUNT, 0) + NVL(A.SERVICE_LABOUR_AMOUNT, 0) + NVL(A.SERVICE_PART_AMOUNT, 0) + NVL(A.SERVICE_OTHER_AMOUNT, 0)) SERVICE_AMOUNT,");
		sql.append("       TO_CHAR(A.END_DATE, 'YYYY-MM-DD') ENDDATE,\n" );
		sql.append("	   NVL(A.NOTE_AMOUNT, A.BALANCE_AMOUNT) NOTEAMOUNT,a.invoice_maker\n");
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A\n" );
		sql.append(" LEFT OUTER JOIN TT_AS_WR_BALANCE_AUTHITEM B ON A.ID=B.BALANCE_ID \n");
		sql.append("WHERE A.ID = ? \n");
		sql.append(" order by b.auth_time desc");
		
		List parList=new ArrayList();
		parList.add(Constant.CLA_TYPE_07);//售前维修
		parList.add(Constant.CLA_TYPE_01);//一般维修
		parList.add(Constant.CLA_TYPE_09);//外出维修
		parList.add(Constant.CLA_TYPE_02);//免费保养
		parList.add(Constant.CLA_TYPE_06);//服务活动
		parList.add(Constant.FEE_TYPE_02);//特殊费用 外出
		parList.add(Constant.FEE_TYPE_01);//特殊费用  市场公单
		parList.add(Constant.FEE_TYPE_02);//特殊费用 外出
		parList.add(Constant.FEE_TYPE_01);//特殊费用  市场公单
		parList.add(Long.valueOf(id));
		
		Map<String, Object> map = pageQueryMap(sql.toString(), parList, getFunName());
		return map;
	}
	
	public Map<String, Object> getBalancePrintMap(String id){
		StringBuffer sql= new StringBuffer();
		sql.append("SELECT A.*, (NVL(A.FREE_DEDUCT,0) + NVL(A.SERVICE_DEDUCT, 0) + NVL(A.CHECK_DEDUCT,0) + NVL(A.OLD_DEDUCT,0) + NVL(A.ADMIN_DEDUCT,0)) DEDUCT,\n" );
		sql.append("       TO_CHAR(A.CREATE_DATE, 'YYYY-MM-DD') CREATEDATE,\n" );
		sql.append("       TO_CHAR(A.START_DATE, 'YYYY-MM-DD') STARTDATE,\n" );
		sql.append("       (A.AMOUNT_SUM - A.RETURN_AMOUNT) ABC,\n" );
		sql.append("       (NVL(A.MARKET_AMOUNT, 0) + NVL(A.APPEND_AMOUNT, 0)) DECLARE_SUM1,\n" );
		sql.append("       (NVL(A.SERVICE_FIXED_AMOUNT, 0) + NVL(A.SERVICE_LABOUR_AMOUNT, 0) + NVL(A.SERVICE_PART_AMOUNT, 0) + NVL(A.SERVICE_OTHER_AMOUNT, 0)) SERVICE_AMOUNT,\n" );
		sql.append("       TO_CHAR(A.END_DATE, 'YYYY-MM-DD') ENDDATE,\n" );
		sql.append("       NVL(A.NOTE_AMOUNT, A.BALANCE_AMOUNT) NOTEAMOUNT,\n" );
		sql.append("       NVL(B.BCOUNT, 0) BCOUNT, NVL(C.CCOUNT, 0) CCOUNT,NVL(D.DCOUNT, 0) DCOUNT,NVL(E.ECOUNT, 0) ECOUNT,NVL(F.FCOUNT, 0) FCOUNT,\n" );
		/*******add by liuxh 20201207 增加*******/
		sql.append("       (SELECT T.DEALER_CODE FROM TM_DEALER T WHERE A.KP_DEALER_ID=T.DEALER_ID) AS KP_DEALER_CODE,\n ");
		sql.append("       (SELECT COUNT(1) FROM TT_AS_WR_SPEFEE K WHERE K.CLAIMBALANCE_ID=A.ID) AS SP_COUNT,\n ");//特殊工单数
		sql.append("       ((NVL(MARKET_AMOUNT_BAK,0)-NVL(MARKET_AMOUNT,0))+(NVL(SPEOUTFEE_AMOUNT_BAK,0)-NVL(SPEOUTFEE_AMOUNT,0))) AS SP_QK,\n"); //特殊费用扣款
		sql.append("       (NVL(RETURN_AMOUNT_BAK,0)-NVL(RETURN_AMOUNT,0)) AS RETURN_QK,\n"); //运费扣款
		 
//		sql.append("       (NVL(LABOUR_AMOUNT_BAK,0)+NVL(PART_AMOUNT_BAK,0)+NVL(OTHER_AMOUNT_BAK,0)+NVL(FREE_AMOUNT_BAK,0)+NVL(MARKET_AMOUNT_BAK,0)+NVL(SPEOUTFEE_AMOUNT_BAK,0)+NVL(APPEND_AMOUNT_BAK,0)+NVL(SERVICE_TOTAL_AMOUNT_BAK,0)+NVL(APPEND_LABOUR_AMOUNT_BAK,0))-"); //审核扣款
//		sql.append("(NVL(LABOUR_AMOUNT,0)+NVL(PART_AMOUNT,0)+NVL(OTHER_AMOUNT,0)+NVL(FREE_AMOUNT,0)+NVL(MARKET_AMOUNT,0)+NVL(SPEOUTFEE_AMOUNT,0)+NVL(APPEND_AMOUNT,0)+NVL(SERVICE_TOTAL_AMOUNT,0)+NVL(APPEND_LABOUR_AMOUNT,0)) AS CHECK_KKS,\n"); //
		sql.append("       (NVL(LABOUR_AMOUNT_BAK,0)+NVL(PART_AMOUNT_BAK,0)+NVL(OTHER_AMOUNT_BAK,0)+NVL(FREE_AMOUNT_BAK,0)+NVL(APPEND_AMOUNT_BAK,0)+NVL(SERVICE_TOTAL_AMOUNT_BAK,0)+NVL(APPEND_LABOUR_AMOUNT_BAK,0))-"); //审核扣款
		sql.append("(NVL(LABOUR_AMOUNT,0)+NVL(PART_AMOUNT,0)+NVL(OTHER_AMOUNT,0)+NVL(FREE_AMOUNT,0)+NVL(APPEND_AMOUNT,0)+NVL(SERVICE_TOTAL_AMOUNT,0)+NVL(APPEND_LABOUR_AMOUNT,0)) AS CHECK_KKS,\n"); //
		/*******add by liuxh 20201207 增加*******/ 
		/*********Iverson add 2010-11-24 添加查询出经销商代码和审核人********************/
		sql.append("       (select t.dealer_code from tm_dealer t where A.dealer_id=t.dealer_id) AS dealer_code, ");
		sql.append("       (select y.auth_person_name from Tt_As_Wr_Balance_Authitem y where y.balance_id = '"+id+"'  and y.auth_time=(select max(g.AUTH_TIME) FROM Tt_As_Wr_Balance_Authitem g WHERE g.balance_id=Y.balance_id)) as USER_NAME ");
		/*********Iverson add 2010-11-24 添加查询出经销商代码和审核人********************/
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A,tm_dealer t,\n" );
		sql.append("     (\n" );
		sql.append("       SELECT B.BALANCE_ID, COUNT(A.ID) BCOUNT\n" );
		sql.append("       FROM TT_AS_WR_APPLICATION A, TR_BALANCE_CLAIM B\n" );
		sql.append("       WHERE A.ID = B.CLAIM_ID\n" );
		sql.append("       AND A.CLAIM_TYPE = ").append(Constant.CLA_TYPE_01).append("--售前维修\n" );
		sql.append("       AND B.BALANCE_ID = ").append(id).append("\n");
		sql.append("       GROUP BY B.BALANCE_ID\n" );
		sql.append("      ) B,\n" );
		sql.append("     (\n" );
		sql.append("       SELECT B.BALANCE_ID, COUNT(A.ID) CCOUNT\n" );
		sql.append("       FROM TT_AS_WR_APPLICATION A, TR_BALANCE_CLAIM B\n" );
		sql.append("       WHERE A.ID = B.CLAIM_ID\n" );
		sql.append("       AND A.CLAIM_TYPE = ").append(Constant.CLA_TYPE_07).append("--售前维修\n" );
		sql.append("       AND B.BALANCE_ID = ").append(id).append("\n");
		sql.append("       GROUP BY B.BALANCE_ID\n" );
		sql.append("      ) C,\n" );
		sql.append("     (\n" );
		sql.append("       SELECT B.BALANCE_ID, COUNT(A.ID) DCOUNT\n" );
		sql.append("       FROM TT_AS_WR_APPLICATION A, TR_BALANCE_CLAIM B\n" );
		sql.append("       WHERE A.ID = B.CLAIM_ID\n" );
		sql.append("       AND A.CLAIM_TYPE = ").append(Constant.CLA_TYPE_09).append("--外出维修\n" );
		sql.append("       AND B.BALANCE_ID = ").append(id).append("\n");
		sql.append("       GROUP BY B.BALANCE_ID\n" );
		sql.append("      ) D,\n" );
		sql.append("     (\n" );
		sql.append("       SELECT B.BALANCE_ID, COUNT(A.ID) ECOUNT\n" );
		sql.append("       FROM TT_AS_WR_APPLICATION A, TR_BALANCE_CLAIM B\n" );
		sql.append("       WHERE A.ID = B.CLAIM_ID\n" );
		sql.append("       AND A.CLAIM_TYPE = ").append(Constant.CLA_TYPE_02).append("--免费保养\n" );
		sql.append("       AND B.BALANCE_ID = ").append(id).append("\n");
		sql.append("       GROUP BY B.BALANCE_ID\n" );
		sql.append("      ) E,\n" );
		sql.append("     (\n" );
		sql.append("       SELECT B.BALANCE_ID, COUNT(A.ID) FCOUNT\n" );
		sql.append("       FROM TT_AS_WR_APPLICATION A, TR_BALANCE_CLAIM B\n" );
		sql.append("       WHERE A.ID = B.CLAIM_ID\n" );
		sql.append("       AND A.CLAIM_TYPE = ").append(Constant.CLA_TYPE_06).append("--服务活动\n" );
		sql.append("       AND B.BALANCE_ID = ").append(id).append("\n");
		sql.append("       GROUP BY B.BALANCE_ID\n" );
		sql.append("      ) F\n" );
		sql.append("WHERE A.ID = B.BALANCE_ID(+)\n" );
		sql.append("AND A.ID = C.BALANCE_ID(+)\n" );
		sql.append("AND A.ID = D.BALANCE_ID(+)\n" );
		sql.append("AND A.ID = E.BALANCE_ID(+)\n" );
		sql.append("AND A.ID = F.BALANCE_ID(+)\n" );
		sql.append("AND A.ID = ").append(id).append("\n");

		Map<String, Object> map = pageQueryMap(sql.toString(), null, getFunName());
		return map;
	}
	
	public List<Map<String, Object>> getBalanceMainList(String id){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT ROWNUM NUM, A.*, (NVL(A.SERVICE_FIXED_AMOUNT, 0) + NVL(A.SERVICE_LABOUR_AMOUNT, 0) + NVL(A.SERVICE_PART_AMOUNT, 0) + NVL(A.SERVICE_OTHER_AMOUNT, 0)) SERVICE_AMOUNT FROM Tt_As_Wr_Balance_Detail_Bak A ");
		sql.append("WHERE BALANCE_ID = ").append(id);
		logger.info("------------"+sql.toString());
		List<Map<String, Object>> list = pageQuery(sql.toString(), null, getFunName());
		return list;
	}
	public List<Map<String, Object>> getBalanceMainList1(String id){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT ROWNUM NUM, A.*, (NVL(A.SERVICE_FIXED_AMOUNT, 0) + NVL(A.SERVICE_LABOUR_AMOUNT, 0) + NVL(A.SERVICE_PART_AMOUNT, 0) + NVL(A.SERVICE_OTHER_AMOUNT, 0)) SERVICE_AMOUNT FROM Tt_As_Wr_Claim_Balance_Detail A ");
		sql.append("WHERE BALANCE_ID = ").append(id);
		logger.info("------------"+sql.toString());
		List<Map<String, Object>> list = pageQuery(sql.toString(), null, getFunName());
		return list;
	}
	
	public String getNewVar(String id, String var){
		String i = "";
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT VAR FROM TT_AS_WR_CLAIM_BALANCE\n");
		sql.append("WHERE ID = ").append(id).append("\n");
		Map<String, Object> map = pageQueryMap(sql.toString(), null, getFunName());
		if(map!=null&&map.size()>0){
			i = String.valueOf(map.get("VAR"));
		}
		return i;
	}
	
	public Map<String, Object> getDealerQueryInfo(String id){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT TO_CHAR(A.BALANCE_AMOUNT, 'FM99,999,990.00') BALANCEAMOUNT,\n");
		sql.append("       TO_CHAR(A.FINANCIAL_DEDUCT, 'FM99,999,990.00') FINANCIALDEDUCT,\n");
		sql.append("       TO_CHAR(A.NOTE_AMOUNT, 'FM99,999,990.00') NOTEAMOUNT,\n");
		sql.append("       TO_CHAR(A.UPDATE_DATE, 'YYYY-MM-DD') UPDATE_DATE,\n");
		sql.append("       A.*, B.NAME,NVL(C.DEALER_CODE, A.DEALER_CODE) DEALER_CODE, c.DEALER_NAME dealer_name1\n");
		sql.append("FROM TT_AS_WR_CLAIM_BALANCE A, TC_USER B, TM_DEALER C\n");
		sql.append("WHERE A.UPDATE_BY = B.USER_ID(+)\n");
		sql.append("AND A.DEALER_ID = C.DEALER_ID(+)\n");
		sql.append("AND A.ID = ").append(id).append("\n"); 
		

		Map<String, Object> map = pageQueryMap(sql.toString(), null, getFunName());
		return map;
	}
	
	/**
	 * 
	* @Title: getMarketFee 
	* @Description: TODO(获取市场工单处理费用) 
	* @param TtIfMarketBean: dealerId 
	* @return Map<String,Object>    返回状态为[技术支持室通过]的市场工单总金额
	* @throws 
	 */
	public Map<String, Object> getMarketFee(TtIfMarketBean bean) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT SUM(MONEY) SUM_MONEY\n" );
		sql.append("FROM TT_IF_MARKET\n" );
		sql.append("WHERE DEALER_ID = ").append(bean.getDealer_id()).append("\n"); 
		sql.append("  AND STATUS = ").append(Constant.MARKET_BACK_STATUS_TECH_PASS);
		Map<String, Object> map = pageQueryMap(sql.toString(), null, getFunName());
		return map;
	}
	
	/**
	 * 
	* @Title: getinvoiceView 
	* @Description: TODO() 
	* @param String: id 
	* @return Map<String,Object>  
	* @throws TT_AS_WR_CLAIM_BALANCE
	 */
	public List<Map<String, Object>> getinvoiceView(String id) {
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT b.*,u.name,D.DEALER_NAME AS DEALER_NAME1 FROM TT_AS_WR_CLAIM_BALANCE b,tc_user u,TM_DEALER D where D.DEALER_ID = B.DEALER_ID AND b.update_by=u.user_id and id="+id);
		List<Map<String, Object>> list = pageQuery(sql.toString(), null, getFunName());
		return list;
	}
	
	@Deprecated
	public List<Map<String, Object>> getinvoiceUnit(String id) {
		StringBuffer sql = new StringBuffer();
		sql.append("select *\n");
		sql.append("  from tm_dealer de where de.dealer_level=10851001\n" );
		sql.append(" start with de.dealer_id = 2010092000801713\n" );
		sql.append("connect by prior de.dealer_id = de.parent_dealer_d");
		List<Map<String, Object>> list = pageQuery(sql.toString(), null, getFunName());
		return list;
	}
	
	/**
	 * 根据结算单ID查询结算单
	 * @param balanceId 结算ID
	 * @return
	 */
	public TtAsWrClaimBalancePO getClaimBalancePOById(Long balanceId){
		
		TtAsWrClaimBalancePO resultPO = null;
		
		TtAsWrClaimBalancePO conditionPO = new TtAsWrClaimBalancePO();
		conditionPO.setId(balanceId);
		
		List<TtAsWrClaimBalancePO> resultList = this.select(conditionPO);
		if(resultList!=null && resultList.size()>0){
			resultPO = resultList.get(0);
		}
		
		return resultPO;
	}

	/**
	 * 查询已经结算的特殊费用工单数和费用，用于检测是否所有特殊费用都已检测完成
	 * @param balanceId 结算单ID
	 * @return Map<String,Object>
	 *         KEY : {ALLCOUNT:该结算单标识的所有特殊费用工单数,AUTH_COUNT:审核通过的特殊费用工单数,
	 *               MARKETFEE:该结算单标识的所有市场工单费用,OUTFEE:该结算单标识的所有外出费用,
	 *               AUTH_MARKETFEE:审核通过的市场工单费用,AUTH_OUTFEE:审核通过的外出费用}
	 */
	public Map<String,Object> queryAuthSpecAmount(Long balanceId){
		
		if(balanceId==null)
			return new HashMap<String, Object>();
		StringBuilder sql= new StringBuilder();
		sql.append("SELECT COUNT(*) ALLCOUNT,\n" );
		//大区退回、结算室退回和已结算状态的特殊费用工单为终止状态
		sql.append("       COUNT(DECODE(STATUS,"+Constant.SPEFEE_STATUS_03+",1 ,"+Constant.SPEFEE_STATUS_05+", 1, "
				+Constant.SPEFEE_STATUS_06+", 1, NULL)) AUTH_COUNT,\n" );
		//统计所有市场工单费用
		sql.append("       NVL(SUM(DECODE(FEE_TYPE, "+Constant.FEE_TYPE_01+", DECLARE_SUM, 0)), 0) MARKETFEE,\n" );
		//统计所有外出特殊费用
		sql.append("       NVL(SUM(DECODE(FEE_TYPE, "+Constant.FEE_TYPE_02+", DECLARE_SUM, 0)), 0) OUTFEE,\n" );
		//统计审核通过的市场工单费用
		sql.append("       NVL(SUM(CASE WHEN FEE_TYPE="+Constant.FEE_TYPE_01+" AND STATUS="+Constant.SPEFEE_STATUS_06+" THEN DECLARE_SUM\n" );
		sql.append("       ELSE 0 END),0) AUTH_MARKETFEE,\n" );
		//统计审核通过的外出费用
		sql.append("       NVL(SUM(CASE WHEN FEE_TYPE="+Constant.FEE_TYPE_02+" AND STATUS="+Constant.SPEFEE_STATUS_06+" THEN DECLARE_SUM\n" );
		sql.append("       ELSE 0 END),0) AUTH_OUTFEE\n" );
		sql.append("  FROM TT_AS_WR_SPEFEE\n" );
		sql.append(" WHERE 1 = 1\n" );
		sql.append("   AND CLAIMBALANCE_ID = ?");

		List<Object> paramList = new ArrayList<Object>();
		paramList.add(balanceId);
		return this.pageQueryMap(sql.toString(), paramList, this.getFunName());
	}
	/**
	 * Iverson add By 2010-12-02
	 * 用于判断限制复核申请的条件
	 * @param balanceId
	 * @return
	 */
	public String dealerTimeJuge(long balanceId){
		String msg="";
		TtAsWrClaimBalancePO ba=new TtAsWrClaimBalancePO();
		ba.setId(Long.valueOf(balanceId));
		ba=(TtAsWrClaimBalancePO)this.select(ba).get(0);
		Date dateEnd=ba.getEndDate();//本次结算时间
		String sql="SELECT END_DATE AS END_DATE FROM TT_AS_WR_CLAIM_BALANCE WHERE DEALER_ID=? AND  ID<>? AND STATUS IN" +
				"(?,?,?,?,?,?,?) ORDER BY END_DATE DESC";
		List parList=new ArrayList();
		parList.add(ba.getDealerId());
		parList.add(balanceId);
		parList.add(Constant.ACC_STATUS_01);
		parList.add(Constant.ACC_STATUS_02);
		parList.add(Constant.ACC_STATUS_05);
		parList.add(Constant.ACC_STATUS_06);
		parList.add(Constant.ACC_STATUS_07);
		parList.add(Constant.ACC_STATUS_08);
		parList.add(Constant.ACC_STATUS_09);
		List listSel=this.pageQuery(sql, parList, this.getFunName());
		//判断在此结算单结算室审核中和结算室审核完成之前是否还有未复核申请的结算单(根据经销商ID和产地)
		//if(listSel.size()>0){
			//Date maxDate=(Date)(((Map)listSel.get(0)).get("END_DATE"));
			//if(dateEnd.after(maxDate)){
				//msg="01";
			//}
		//}
		//判断旧件审核时间加上6个月是否小于现在的结算时间，是表示为过期可以结算，反之不能结算
		if(msg.equals("")){
			sql="SELECT OLD_REVIEW_DATE FROM TT_AS_DEALER_TYPE WHERE  DEALER_ID=? AND YIELDLY=?";
			List listPar2=new ArrayList();
			listPar2.add(ba.getDealerId());
			listPar2.add(ba.getYieldly());
			List listDate=this.pageQuery(sql, listPar2, this.getFunName());
			Date parDate=(Date)((Map)listDate.get(0)).get("OLD_REVIEW_DATE");
		
			Calendar calendar = Calendar.getInstance();//公用类，加年月日的
			calendar.setTime(parDate);
			calendar.add(Calendar.MONTH, 6);//加6个月
			parDate = calendar.getTime();//得到加一天后的值
			if(parDate.before(dateEnd)){
				msg="02";
			}	
		}
		//判断结算的开始时间是否等于上一次结算时间加一天
		if(msg.equals("")){
			Date startDate=ba.getStartDate();
			sql="SELECT BALANCE_REVIEW_DATE FROM TT_AS_DEALER_TYPE WHERE  DEALER_ID=? AND YIELDLY=?";
			List listPar2=new ArrayList();
			listPar2.add(ba.getDealerId());
			listPar2.add(ba.getYieldly());
			List listDate=this.pageQuery(sql, listPar2, this.getFunName());
			Date parDate=(Date)((Map)listDate.get(0)).get("BALANCE_REVIEW_DATE");
		
			Calendar calendar = Calendar.getInstance();//公用类，加年月日的
			calendar.setTime(parDate);
			calendar.add(Calendar.DAY_OF_MONTH, 1);//时间加一天
			parDate = calendar.getTime();//得到加一天后的值
			if(!parDate.equals(startDate)){
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				calendar.setTime(startDate);
				calendar.add(Calendar.DAY_OF_MONTH, -1);//时间减一天
				startDate = calendar.getTime();//得到减一天后的值
				String sql1="SELECT count(*) as count FROM tt_as_changedate WHERE CHANGE_REVIEW_DATE in(to_date('"+sdf.format(startDate)+"','YYYY-MM-DD')) and DEALER_ID='"+ba.getDealerId()+"' AND YIELDLY='"+ba.getYieldly()+"'";
				System.out.println("sqlslq=="+sql1);
				List time=this.pageQuery(sql1, null, this.getFunName());
				String count=((Map)time.get(0)).get("COUNT").toString();
				if(Integer.parseInt(count)>0){
					//判断在此时间之前还有没有没有需要复核申请的结算单
					//如果有就提示它不能跨月复核
					//没有就可以复核
					String sql12="SELECT change_date FROM tt_as_changedate WHERE CHANGE_REVIEW_DATE =to_date('"+sdf.format(startDate)+"','YYYY-MM-DD') and DEALER_ID='"+ba.getDealerId()+"' AND YIELDLY='"+ba.getYieldly()+"'";
					System.out.println("sqlslq=="+sql12);
					List time2=this.pageQuery(sql12, null, this.getFunName());
					String change_date=((Map)time2.get(0)).get("CHANGE_DATE").toString();
					try{
						calendar.setTime(sdf.parse(change_date));
					}catch(Exception e){
						e.printStackTrace();
					}
					calendar.add(Calendar.DAY_OF_MONTH, -1);//时间减一天
					Date change_date1 = calendar.getTime();//得到减一天后的值
					String sql13="SELECT count(*) as count FROM tt_as_wr_claim_balance WHERE end_DATE in(to_date('"+sdf.format(change_date1)+"','YYYY-MM-DD')) and DEALER_ID='"+ba.getDealerId()+"' AND STATUS IN("+Constant.ACC_STATUS_01+","+Constant.ACC_STATUS_02+","+Constant.ACC_STATUS_06+","+Constant.ACC_STATUS_07+","+Constant.ACC_STATUS_08+","+Constant.ACC_STATUS_09+")  AND YIELDLY='"+ba.getYieldly()+"'";
					System.out.println("sqlslq=="+sql13);
					List time3=this.pageQuery(sql13, null, this.getFunName());
					String count3=((Map)time3.get(0)).get("COUNT").toString();
					if(Integer.parseInt(count3)>0){
						msg="03";
					}
				}else{
					msg="03";
				}
			}	
		}
		//判断经销商时候被停职结算
		if(msg.equals("")){
			sql="SELECT STATUS FROM tt_as_dealer_type WHERE  DEALER_ID=? AND YIELDLY=?";
			List listPar3=new ArrayList();
			listPar3.add(ba.getDealerId());
			listPar3.add(ba.getYieldly());
			List listDate=this.pageQuery(sql, listPar3, this.getFunName());
			String status=(String)((Map)listDate.get(0)).get("STATUS");
			if(status.equals(Constant.IF_TYPE_YES.toString())){
				msg="04";
			}	
		}
		
		return msg;
	}
	public PageResult<Map<String,Object>> getClaimPrint(String bDate,String eDate,String name,Long comId,int pageSize,int curPage,Long poseId){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select /*+RULE*/b.total_no,\n");
		sql.append("       d.dealer_code,\n");  
		sql.append("       d.dealer_name,\n");  
		sql.append("       to_char(d.begin_balance_date,'yyyy-MM-dd') b_date,\n");  
		sql.append("       to_char(d.end_balance_date,'yyyy-MM-dd') e_date,\n");  
		sql.append("       b.claim_count,\n");  
		sql.append("       to_char(b.sign_date,'yyyy-MM-dd') sign_date,\n");
		sql.append("       r.region_name,u.name\n");  
		sql.append("  from Tt_As_Wr_Gather_Balance b, tc_user u, tm_dealer d,tm_region r\n");  
		sql.append(" where b.dealer_id = d.dealer_id\n");  
		sql.append("   and b.status in ("+Constant.BALANCE_GATHER_TYPE_03+","+Constant.BALANCE_GATHER_TYPE_04+")\n");  
		sql.append("   and u.user_id = b.sign_person\n");  
		if(StringUtil.notNull(bDate))
			sql.append("   and b.sign_date>=to_date('"+bDate+"','yyyy-MM-dd')\n");
		if(StringUtil.notNull(eDate))
			sql.append("   and b.sign_date<=to_date('"+eDate+" 23:59:59','yyyy-MM-dd hh24:mi:ss')\n");
		if(StringUtil.notNull(name))
			sql.append("   and u.name like '%"+name+"%'\n");
		sql.append("   and d.Province_ID = r.region_code\n");
		sql.append("   and b.oem_company_id="+comId+"\n");
		sql.append(" and  exists (select t.produce_base \n" );
		sql.append("       from tm_business_area t,tm_pose_business_area t1 \n");
		sql.append("       where T.AREA_ID=T1.AREA_ID \n");
		sql.append("       and T1.POSE_ID="+poseId+" \n");
		sql.append("       and t.status = 10011001 \n");
		sql.append("       and B.YIELDLY=T.PRODUCE_BASE \n");
		sql.append("   ) \n");

		sql.append(" order by d.province_id,u.user_id,d.dealer_code desc\n");
		return this.pageQuery(sql.toString(),null,this.getFunName(), pageSize, curPage);

	}
	
	/**
	 * Iverson add By 2010-12-16
	 * 打印收票报表(查询分页)
	 */
	public PageResult<Map<String,Object>> printPorterQuery(String bDate,String eDate,String name,String report_code,String financeName,String gzDate,String gzDate1,Long comId,int pageSize,int curPage,Long poseId){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select /*+RULE*/ttt.report_code,ttt.dealer_code,ttt.dealer_name,ttt.region_name,ttt.invoice_code,ttt.amount,ttt.tax_rate,ttt.auth_time,min(ttt.auth_person_name) auth_person_name,ttt.a_name,to_char(ttt.gzTime,'yyyy-MM-dd') as gzTime from (\n");
		sql.append("select b.report_code ,t.dealer_code,t.dealer_name,r.region_name,b.invoice_code,b.amount,tt.tax_rate,to_char(a.auth_time,'yyyy-MM-dd') as auth_time,bb.auth_person_name,a.auth_person_name as a_name, \n");
		sql.append("(select max(fff.auth_time) from tt_taxable_sum_authitem fff where fff.auth_status='"+Constant.TAXABLE_SERVICE_SUM_FANCE+"' and a.balance_id=fff.balance_id) gzTime \n");
		sql.append("from tt_taxable_sum_authitem a,tt_labor_list b ,tm_dealer t,tm_region r, \n");  
		sql.append("tt_taxable_service_sum tt,tt_as_wr_balance_authitem bb,tt_labor_list_detail cc,tt_as_wr_claim_balance dd,tt_labor_list_detail td \n");  
		sql.append("where a.balance_id=b.report_id \n");  
		sql.append("and b.dealer_id=t.dealer_id and t.province_id=r.region_code and a.balance_id=tt.sum_parameter_id \n");  
		sql.append("and dd.balance_no=cc.balance_no and bb.balance_id=dd.id and td.report_id = b.report_id and td.balance_id = dd.id and bb.auth_status='"+BalanceStatusRecord.STATUS_07+"' and a.auth_status = '"+Constant.TAXABLE_SERVICE_SUM_GET+"' \n");  
		if(StringUtil.notNull(bDate)){
			sql.append("and a.auth_time>=to_date('"+bDate+" 00:00:00','yyyy-MM-dd hh24:mi:ss') \n");
		}
		if(StringUtil.notNull(eDate)){
			sql.append("and a.auth_time<=to_date('"+eDate+" 23:59:59','yyyy-MM-dd hh24:mi:ss') \n");
		}
		if(StringUtil.notNull(name)){
			sql.append("and a.auth_person_name like '%"+name+"%' \n");
		}
		if(StringUtil.notNull(financeName)){
			sql.append("and bb.auth_person_name like '%"+financeName+"%' \n");
		}
		if(StringUtil.notNull(report_code)){
			sql.append("and b.report_code like '%"+report_code+"%' \n");
		}
		sql.append("and dd.yieldly in (select t.produce_base from tm_business_area t where t.area_id in (select area_id from tm_pose_business_area where pose_id = "+poseId+") and t.status = "+Constant.STATUS_ENABLE+")) ttt where 1=1\n");
		if(StringUtil.notNull(gzDate)){
			sql.append("and ttt.gzTime >= to_date('"+gzDate+" 00:00:00','yyyy-MM-dd hh24:mi:ss') \n");
		}
		if(StringUtil.notNull(gzDate1)){
			sql.append("and ttt.gzTime <= to_date('"+gzDate1+" 23:59:59','yyyy-MM-dd hh24:mi:ss') \n");
		}
		sql.append("group by ttt.report_code,\n");
		sql.append("      ttt.dealer_code,\n");  
		sql.append("      ttt.dealer_name,\n");  
		sql.append("      ttt.region_name,\n");  
		sql.append("      ttt.invoice_code,\n");  
		sql.append("      ttt.amount,\n");  
		sql.append("      ttt.tax_rate,\n");  
		sql.append("      ttt.auth_time,\n");  
		sql.append("      ttt.a_name,\n");   
		sql.append("      ttt.gzTime\n");   
		ClaimBillMaintainDAO dao = new ClaimBillMaintainDAO();
		 List<Map<String,Object>> list = dao.queryTcCode();
		 if(Integer.valueOf(list.get(0).get("CODE_ID").toString())==(Constant.chana_jc)){
			 sql.append("order by min(ttt.auth_person_name),ttt.region_name \n");
		 }
		 else{
			 sql.append("order by min(ttt.auth_person_name),ttt.auth_time,ttt.region_name,ttt.dealer_name\n");
		 }
		System.out.println("sqlsql=="+sql.toString());
		return this.pageQuery(sql.toString(),null,this.getFunName(), pageSize, curPage);
	}
	public List<Map<String,Object>> exportExcel(String bDate,String eDate,String name,String report_code,String financeName,String gzDate,String gzDate1,Long comId,int pageSize,int curPage,Long poseId){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select /*+RULE*/ttt.report_code,ttt.dealer_code,ttt.dealer_name,ttt.region_name,ttt.invoice_code,ttt.amount,ttt.tax_rate,ttt.auth_time,min(ttt.auth_person_name) auth_person_name,ttt.a_name,to_char(ttt.gzTime,'yyyy-MM-dd') as gzTime from (\n");
		sql.append("select b.report_code ,t.dealer_code,t.dealer_name,r.region_name,b.invoice_code,b.amount,tt.tax_rate,to_char(a.auth_time,'yyyy-MM-dd') as auth_time,bb.auth_person_name,a.auth_person_name as a_name, \n");
		sql.append("(select max(fff.auth_time) from tt_taxable_sum_authitem fff where fff.auth_status='"+Constant.TAXABLE_SERVICE_SUM_FANCE+"' and a.balance_id=fff.balance_id) gzTime \n");
		sql.append("from tt_taxable_sum_authitem a,tt_labor_list b ,tm_dealer t,tm_region r, \n");  
		sql.append("tt_taxable_service_sum tt,tt_as_wr_balance_authitem bb,tt_labor_list_detail cc,tt_as_wr_claim_balance dd,tt_labor_list_detail td \n");  
		sql.append("where a.balance_id=b.report_id \n");  
		sql.append("and b.dealer_id=t.dealer_id and t.province_id=r.region_code and a.balance_id=tt.sum_parameter_id \n");  
		sql.append("and dd.balance_no=cc.balance_no and bb.balance_id=dd.id and td.report_id = b.report_id and td.balance_id = dd.id and bb.auth_status='"+BalanceStatusRecord.STATUS_07+"' and a.auth_status = '"+Constant.TAXABLE_SERVICE_SUM_GET+"' \n");  
		if(StringUtil.notNull(bDate)){
			sql.append("and a.auth_time>=to_date('"+bDate+" 00:00:00','yyyy-MM-dd hh24:mi:ss') \n");
		}
		if(StringUtil.notNull(eDate)){
			sql.append("and a.auth_time<=to_date('"+eDate+" 23:59:59','yyyy-MM-dd hh24:mi:ss') \n");
		}
		if(StringUtil.notNull(name)){
			sql.append("and a.auth_person_name like '%"+name+"%' \n");
		}
		if(StringUtil.notNull(financeName)){
			sql.append("and bb.auth_person_name like '%"+financeName+"%' \n");
		}
		if(StringUtil.notNull(report_code)){
			sql.append("and b.report_code like '%"+report_code+"%' \n");
		}
		sql.append("and dd.yieldly in (select t.produce_base from tm_business_area t where t.area_id in (select area_id from tm_pose_business_area where pose_id = "+poseId+") and t.status = "+Constant.STATUS_ENABLE+")) ttt where 1=1\n");
		if(StringUtil.notNull(gzDate)){
			sql.append("and ttt.gzTime >= to_date('"+gzDate+" 00:00:00','yyyy-MM-dd hh24:mi:ss') \n");
		}
		if(StringUtil.notNull(gzDate1)){
			sql.append("and ttt.gzTime <= to_date('"+gzDate1+" 23:59:59','yyyy-MM-dd hh24:mi:ss') \n");
		}
		sql.append("group by ttt.report_code,\n");
		sql.append("      ttt.dealer_code,\n");  
		sql.append("      ttt.dealer_name,\n");  
		sql.append("      ttt.region_name,\n");  
		sql.append("      ttt.invoice_code,\n");  
		sql.append("      ttt.amount,\n");  
		sql.append("      ttt.tax_rate,\n");  
		sql.append("      ttt.auth_time,\n");  
		sql.append("      ttt.a_name,\n");   
		sql.append("      ttt.gzTime\n");   
		ClaimBillMaintainDAO dao = new ClaimBillMaintainDAO();
		 List<Map<String,Object>> list = dao.queryTcCode();
		 if(Integer.valueOf(list.get(0).get("CODE_ID").toString())==(Constant.chana_jc)){
			 sql.append("order by min(ttt.auth_person_name),ttt.region_name \n");
		 }
		 else{
			 sql.append("order by min(ttt.auth_person_name),ttt.auth_time,ttt.region_name,ttt.dealer_name\n");
		 }
		System.out.println("sqlsql=="+sql.toString());
		
		return this.pageQuery(sql.toString(), null, this.getFunName());
	}
	
	public List getDate(String id){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select * from tt_as_wr_balance_authitem b where b.balance_id=? and b.auth_status = ? ");
		List list=new ArrayList();
		list.add(Long.valueOf(id));
		list.add(com.infodms.dms.actions.claim.application.BalanceStatusRecord.STATUS_06);
		
		return this.select(TtAsWrBalanceAuthitemPO.class, sql.toString(), list);
	}
	public List getDate2(String id){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select * from tt_as_wr_balance_authitem b where b.balance_id=? and b.auth_status = ? ");
		List list=new ArrayList();
		list.add(Long.valueOf(id));
		list.add(com.infodms.dms.actions.claim.application.BalanceStatusRecord.STATUS_07);
		
		return this.select(TtAsWrBalanceAuthitemPO.class, sql.toString(), list);
	}
	public List getSignInfo(String id){
		StringBuffer sql = new StringBuffer("\n");
		sql.append("select u.name remark,b.sign_date\n");
		sql.append("  from tt_as_wr_claim_balance  a,\n");  
		sql.append("       tt_as_wr_gather_balance b,\n");  
		sql.append("       tr_gather_balance       c,tc_user u\n");  
		sql.append(" where a.id ="+id+"\n");  
		sql.append("   and a.id = c.balance_id\n");  
		sql.append("   and b.id = c.gather_id and u.user_id=b.sign_person\n");
		return this.select(TtAsWrGatherBalancePO.class, sql.toString(), null);
	}
	
	public Map<String,Object> checkNum(String sql){
		return pageQueryMap(sql, null, getFunName());
	}
	
}








